package de.metalcon.gwt.client.modules;

import java.util.ArrayList;
import java.util.Map;

import com.google.gwt.user.client.ui.CaptionPanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;

import de.metalcon.gwt.client.mainDesign.Box;
import de.metalcon.gwt.shared.ContentTransmitter;

public class NodeOverviewModule extends ADynamicModule {
	public NodeOverviewModule(String globalKey) {
		addReuqestVar("globalKey", globalKey);
	}

	@Override
	protected void generateContent() {
		ContentTransmitter transmitter = getContentTransmitter();
		Box box = new Box();
		add(box);
		createNodeBox(transmitter, box);

		CaptionPanel caption = new CaptionPanel("Relations");
		box.add(caption);

		FlowPanel panel = new FlowPanel();
		caption.add(panel);

		for (Map.Entry<String, ArrayList<ContentTransmitter>> entry : transmitter.getAllLists()) {
			CaptionPanel caption2 = new CaptionPanel(entry.getKey());
			panel.add(caption2);
			FlowPanel p = new FlowPanel();
			caption2.add(p);
			for (ContentTransmitter t : entry.getValue()) {
				createNodeBox(t, p);
			}
		}
	}

	private void createNodeBox(ContentTransmitter node, Panel mainbox) {
		CaptionPanel caption = new CaptionPanel(node.getString("GlobalKey"));
		mainbox.add(caption);
		FlowPanel mainflow = new FlowPanel();
		caption.add(mainflow);

		caption = new CaptionPanel("Properties");
		mainflow.add(caption);
		FlowPanel flow = new FlowPanel();
		caption.add(flow);
		for (Map.Entry<String, Object> entry : node.getAllPairs()) {
			Label testContent = new Label(entry.getKey() + " : " + entry.getValue());
			flow.add(testContent);
		}
	}
}
